package cool.taomu.toolkit.jersey

import com.google.auto.service.AutoService
import com.google.inject.AbstractModule
import cool.taomu.toolkit.TaomuConfigure
import cool.taomu.toolkit.jersey.tomcat.JsereyTomcatServer
import cool.taomu.toolkit.jersey.tomcat.TomcatProvider
import cool.taomu.toolkit.platform.inter.AbsPlatform
import cool.taomu.toolkit.platform.inter.IPlatform
import org.apache.catalina.Server

@AutoService(IPlatform)
class JerseryTomcatServerPlugin extends AbsPlatform {

	override note() {
		"Jserey框架Tomcat服务器插件"
	}

	override packages() {
	}

	override module(TaomuConfigure configure) {
		new AbstractModule() {
			override configure() {
				bind(Server).toProvider(TomcatProvider);
				bind(JsereyTomcatServer).asEagerSingleton;
			}
		}
	}

	override start() {
		var inject = this.context.injectorSupplier.get
		val server = inject.getInstance(JsereyTomcatServer)
		this.context.executor.execute([
			server.start();
		])
	}

	override init() {
	}

}
